package cn.tedu.charging.account.controller;

import cn.tedu.charging.account.service.IChargingStationService;
import cn.tedu.charging.web.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Metrics;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.connection.RedisGeoCommands;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class ChargingStationController {

    @Autowired
    private IChargingStationService service;

    /**
     * 根据所给的半径，经度，纬度和充电站的名字来查询所有的充电站
     *
     * @param latitude 纬度
     * @param longitude 经度
     * @param radius 半径
     * @param name 名字
     * @return 返回所有充电站的集合
     */
    @GetMapping("/charging_stations")
    public JsonResult getChargingStations(
            @RequestParam("latitude") double latitude,
            @RequestParam("longitude") double longitude,
            @RequestParam("radius") double radius,
            @RequestParam("name") String name) {
        log.debug("开始查询{}的所有充电站，参数：{}， {}", radius, latitude, longitude, name);
        return JsonResult.ok("查询成功！", service.findByLocationWithin(latitude, longitude, radius, name));
    }

    /**
     * 根据充电枪的id来查询是否可用
     *
     * @param chargingDeviceId 充电枪id
     * @return 充电枪的信息
     */
    @GetMapping("/charging")
    public JsonResult startCharging(@RequestParam("id") long chargingDeviceId) {
        OrderStandardVO a = selectByStationDeviceId(chargingDeviceId);
        if (a == null) {
            a = new OrderStandardVO();

        }
        return JsonResult.ok(a);
    }
}
